/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.BASE64Encoder;

/**
 *
 * @author PhucAn
 */
public class MD5Encryption {

    MessageDigest md;

    public MD5Encryption() {
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(MD5Encryption.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public String encrypt(String valueToEncrypt) {
        String cipherText = "";
        BASE64Encoder en64 = new BASE64Encoder();
        byte[] digestBytes = md.digest(valueToEncrypt.getBytes());
        cipherText = en64.encode(digestBytes);
        return cipherText;

    }

    public String encrypt(char[] charArray) {
        return encrypt(new String(charArray));
    }
}
